﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
using qiupeng.Public;
using System.IO;

public partial class SystemManage_ResponBm_qx : Base
{
    Db List = new Db();
    public static string s_quanbu, PerSessionStr;
    protected void Page_Load(object sender, EventArgs e)
    {


        if (!Page.IsPostBack)
        {


            BindAttribute();
            DataBindToGridview();

            string SQL_GetList = "select * from qp_hr_username   where id='" + int.Parse(Request.QueryString["id"]) + "'";
            
            OleDbDataReader NewReader = List.GetList(SQL_GetList);
            if (NewReader.Read())
            {
                Name.Text = NewReader["XingMing"].ToString();
                PerSessionStr = NewReader["BmQx"].ToString();
            }
            NewReader.Close();



            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                GridViewRow row = GridView1.Rows[i];


                CheckBox Cquanbu = (CheckBox)row.FindControl("quanbu");
                Label Lquanbu = (Label)row.FindControl("quanbuid");//全部

                if (List.StrIFInStr("," + Lquanbu.Text + ",", "," + PerSessionStr + ",") && Lquanbu.Text != "0")
                {
                    Cquanbu.Checked = true;
                }
            }


        }
    }
    public void BindAttribute()
    {

        Button1.Attributes["onclick"] = "javascript:return showwait();";
        Button2.Attributes["onclick"] = "javascript:return showwait();";
    }
    public void DataBindToGridview()
    {
        string sql = "select * from qp_hr_JiGou where parentnodesid!='0'";
        if (Session["ResponseRemark"].ToString() == "局级")
        {

        }
        else
        {
            sql += " and id in (" + this.Session["bmqxa"].ToString().Trim() + ") ";
        }
        //switch (Session["ResponseRemark"].ToString())//根据目前所属的角色查询的
        //{
        //    case "普通":
        //        SqlStrStart += " and status='55' and workernumber='" + Session["StaffNumer"] + "'  ";
        //        SqlStrStartCount += " and status='55'  and workernumber='" + Session["StaffNumer"] + "' ";
        //        break;
        //    case "区队":
        //        SqlStrStart += " and (isnull(status,'0')='0' or isnull(status,'0')='12') and  companyid in ('" + Session["bmqxa"].ToString().Replace(",", "','") + "') ";
        //        SqlStrStartCount += " and (isnull(status,'0')='0' or isnull(status,'0')='12') and  companyid in ('" + Session["bmqxa"].ToString().Replace(",", "','") + "') ";
        //        break;
        //    case "矿级":
        //        SqlStrStart += " and status='1' and  companyid in ('" + Session["bmqxa"].ToString().Replace(",", "','") + "')  ";
        //        SqlStrStartCount += " and status='1'  and  companyid in ('" + Session["bmqxa"].ToString().Replace(",", "','") + "') ";
        //        break;
        //    case "局级":
        //        SqlStrStart += " and status='55'  ";
        //        SqlStrStartCount += " and status='55'";
        //        break;
        //}
        
        sql += "  order by QxString asc ";
        this.GridView1.DataSource = this.List.GetGrid_Pages_not(sql);
        this.GridView1.DataBind();

    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        DataControlRowType itemType = e.Row.RowType;
        if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);";
            e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);";

        }

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];


            CheckBox Cquanbu = (CheckBox)row.FindControl("quanbu");
            Label Lquanbu = (Label)row.FindControl("quanbuid");//全部



            if (Lquanbu.Text == "0")
            { Cquanbu.Visible = false; }
            else
            { Cquanbu.Visible = true; }//全部


        }





    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        s_quanbu = string.Empty;


        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];



            CheckBox Cquanbu = (CheckBox)row.FindControl("quanbu");
            Label Lquanbu = (Label)row.FindControl("quanbuid");//全部


            if (Cquanbu.Checked == true)
            {
                s_quanbu += "," + Lquanbu.Text + "";
            }



        }
        string s_all = string.Empty;
        s_all = s_quanbu;


        string Sql_update1 = "Update qp_hr_username  Set BmQx='0" + s_all + "' where id='" + int.Parse(Request.QueryString["id"]) + "'";
        List.ExeSql(Sql_update1);



        List.InsertLog("设置角色部门权限[" + Name.Text + "]", "角色部门权限");

        this.Response.Write("<script language=javascript>alert('提交成功，您设置的用户，需要重新登陆后才能生效！');window.location.href='ResponBm.aspx'</script>");
    }



    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("ResponBm.aspx");
    }
}
